home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-09-06 | 3.0 KB | 119 lines | [TEXT/MACA] |
- /*
- * cntl.c - control handling for the game of Tablut
- */
-
- #include <quickdraw.h>
- #include <window.h>
- #include <control.h>
- #define ALLDIM 255 /* should be in control.h, but isn't */
- #include <toolutil.h>
- #include <memory.h>
- #include <resource.h>
-
- #include "tablut.h"
-
- #define PLAYCNTL 129 /* Resource ID of the "Play" radio button */
- #define STOPCNTL 130 /* Resource ID of the "Stop" radio button */
- #define LOOKCNTL 131 /* Resource ID of the game scrollbar */
-
- ControlHandle playbutton; /* the Play radio button */
- ControlHandle stopbutton; /* the Stop radio button */
- ControlHandle looker; /* the Look (move browser) scrollbar */
-
- /*
- * getcontrols() - initialize the game controls
- */
- getcontrols()
- {
- playbutton = GetNewControl(PLAYCNTL, mywindow);
- stopbutton = GetNewControl(STOPCNTL, mywindow);
- looker = GetNewControl(LOOKCNTL, mywindow);
- }
-
- /*
- * docontrol() - handle a mouse-click in one of our controls
- */
- docontrol(cntl, part, placep)
- ControlHandle cntl; /* the control that was pressed */
- short part; /* the pressed part of that control */
- Point *placep; /* where the mouse was when pressed */
- {
- short n;
- pascal void trackbrowse();
-
- if (cntl == playbutton || cntl == stopbutton) {
- if (TrackControl(cntl, pass(*placep), (ProcPtr) 0)) {
- setsetup(cntl == stopbutton);
- }
- } else if (cntl == looker) {
- if (part == inThumb) {
- setsetup(1); /* scrolling stops the game */
- if (TrackControl(cntl, pass(*placep), (ProcPtr) 0)) {
- n = GetCtlValue(looker);
- seekboard(n - 1);
- readboard();
- }
- } else {
- setsetup(1); /* scrolling stops the game */
- (void) TrackControl(cntl, pass(*placep), trackbrowse);
- }
- }
- }
-
- /*
- * trackbrowse() - "scroll" through the game as long as the mouse is down
- */
- pascal void
- trackbrowse(cntl, part)
- ControlHandle cntl; /* the touched control */
- short part; /* the touched part */
- {
- short delta; /* number of moves to skip forward or back */
-
- switch (part) {
- case inUpButton: delta = -1; break;
- case inDownButton: delta = 1; break;
- case inPageUp: delta = -2; break;
- case inPageDown: delta = 2; break;
- default: delta = 0; break;
- }
- if (delta) {
- seekboard(curmove - 1 + delta); readboard();
- }
- }
-
- /*
- * setsetup() - put a value into the Play/Stop state & set the button
- * accordingly: If the game is being played, set "Stop"; otherwise, "Play".
- */
- setsetup(newval)
- int newval;
- {
- static int first = 1; /* true if the first time through */
-
- if (winner != NOWIN) newval = 1; /* can't play if somebody has won */
- if (first || insetup != newval) {
- first = 0;
- insetup = newval;
- SetCtlValue(playbutton, !insetup);
- SetCtlValue(stopbutton, insetup);
- }
- }
-
- /*
- * fixlooker() - make the scrollbar reflect the current state of the game
- */
- fixlooker()
- {
- SetCtlMin(looker, 1);
- if (nummoves < 2) {
- HiliteControl(looker, ALLDIM);
- } else {
- HideControl(looker);
- SetCtlMax(looker, nummoves);
- SetCtlValue(looker, curmove);
- HiliteControl(looker, 0);
- ShowControl(looker);
- }
- }
-